Overload constructors for ClusterState and DestinationState to enable unit testing #2198
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This addresses two open issues, #2142 and #1792, related to difficulties in unit testing custom middleware due to the inability to initialize/modify ClusterState and DestinationState.
The
ClusterState
andDestinationState
constructors are now overloaded to accept additional parameters, which enables better unit testing when updating theReverseProxyFeature
viaHttpContextFeaturesExtensions
.However it's worth noting that lifting these restrictions may allow the user to set the state in the
ReverseProxyFeature
that may potentially cause unintended side effects. Once I started diving deeper into the code, it seemed that there is some level of dependency on the immutable design, as there is logic related to making the state eventually consistent; I believe that's why there is some duplicate data such as the clusterId and destination configurations in the nested objects ofClusterState
. But it seems that this potential risk was present before these changes, so it's most likely acceptable in a unit testing context.Here is a sample of leveraging these new constructors in the context of the two open issues
These changes offer better granularity for unit testing through reassigning the
ReverseProxyFeature
with aClusterState
, via creating/modifying theClusterModel
along with itsClusterConfig
, and theDestinationState
s of theAllDestinations
andAllDestinations
properties with their associatedDestinationModel
s andDestinationConfig
s.